<?php
	include '../config.php';
	include 'function.php';
	$uname = $_REQUEST['un'];//医院名称
	$aname = $_REQUEST['an'];//管理员用户名
	$apwd = $_REQUEST['ap'];//管理员密码
	$apwd = md5($apwd);
	
	if(is_ajax()){
		$sql_unit = "insert into UNIT (unit_id,unit_name,unit_state) values(1,'{$uname}',1)";
		$sql_admin = "insert into SYSUSER values(ROLE_SEQ.NEXTVAL,'{$aname}','{$apwd}','医院超级管理员',1,-1,-1,1,1,'','',1)";
		JYDB::execute($sql_unit);
		JYDB::execute($sql_admin);
		$dbpath = '../up-script/install-baseinfo.sql';
		if(read_sql_to_db($dbpath)){
			set_install();
			echo json_encode(array('code'=>1,'msg'=>'suc'));
			exit;
		}
		echo json_encode(array('code'=>-1,'msg'=>'fail'));
		exit;
	}